﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BoneSoft.CSS;
using OpenControls.Core;
using System.Drawing;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace OpenControls
{
    public class Utils
    {
        

        public RuleSet FindRuleSet(IStyle style, string ruleSetName)
        {
            foreach (RuleSet rs in style.CSS.RuleSets)
            {
                if (rs.Selectors[0].ToString().ToLower() == ruleSetName.ToLower())
                    return rs;
            }

            return null;
        }
                        
        /// <summary>
        /// Gets the System.Drawing.Color from the given value.
        /// </summary>
        /// <param name="value">The name or hexadecimal value of the color.</param>
        /// <returns>System.Drawing.Color object with the color or null if the color doesn't exists.</returns>
        public Color? GetColor(string value)
        {
            Color? color;

            if (value.Contains('#'))
            {
                try
                {
                    color = System.Drawing.ColorTranslator.FromHtml(value);
                    return color;
                }
                catch
                {
                    throw;
                }
            }
            else
            {
                try
                {
                    color = Color.FromName(value);
                    return color;
                }
                catch
                {
                    throw;
                }
            }
        }       
    }
}
